using RBACDemo.EntityFrameworkCore;
using RBACDemo.Ability.Docking;
using Youshow.Ace.Ability;
using Youshow.Ace.AutoMapper;
using Youshow.Ace.Modularity;
using Youshow.Ace.Logger;
using Microsoft.Extensions.DependencyInjection;
using Youshow.Ace.AspNetCore.Jwt;

namespace RBACDemo.Ability;

[RelyOn(
    typeof(AceAbilityModule),
    typeof(AceAutoMapperModule),
    typeof(AceLoggerModule),
    typeof(AceAspNetCoreJwtModule), // 添加AceAspNetCoreJwtModule模块
    typeof(RBACDemoAbilityDockingModule),
    typeof(RBACDemoEntityFrameworkCoreModule)
)]
public class RBACDemoAbilityModule : AceModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var services = context.Services;
        services.AddAceLogger(
            opt => opt.UseFile()
                .UseElasticSearch(false)
        );

        // 添加jwt服务
        services.AddJwtAuthentication(opt =>
        {
            opt.UseAuthorizationPolicy(true); // 开启AceFramework默认授权验证
        });
    }
}